package com.dzm.test08.manager;

import com.dzm.test08.entity.User;

/**
 * 作者：Dzm
 * 时间：2024-07-13-10:11
 * 功能：
 */
public class UserManager {
    //存放用户信息
    private User[] users = new User[10];
    //计数器，计算下标
    private int count = 0;

    public UserManager() {
        initial();
    }

    //初始化数据
    private void initial() {
        User user1 = new User("admin", "admin");
        User user2 = new User("root", "root");
        User user3 = new User("root", "123");
        users[count++] = user1;
        users[count++] = user2;
        users[count++] = user3;
    }

    public boolean login(String username, String password) {
        for (User user : users) {
            if(user != null) {
                //用户名和密码是否正确
                if(user.getUsername().equals(username) && user.getPassword().equals(password)) {
                    return true;
                }
            }
        }
        return false;
    }
}
